package zabbix

import (
	"encoding/json"
	"errors"
)

func ScreenitemCreateData() (string,map[string]interface{}) {
	method := "screenitem.create"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "screenid": 16,
        "resourcetype": 0,
        "resourceid": 612,
        "x": 0,
        "y": 0
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func ScreenitemDeleteData() (string,map[string]interface{}) {
	method := "screenitem.delete"
	var data map[string]interface{}
	jsonstr := []byte(`[
        "65",
        "63"
	]`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func ScreenitemUpdatebypositionData() (string,map[string]interface{}) {
	method := "screenitem.updatebyposition"
	var data map[string]interface{}
	jsonstr := []byte(`[
        {
            "screenid": "16",
            "x": 0,
            "y": 0,
            "resourceid": "644"
        }	]`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func ScreenitemUpdateData() (string,map[string]interface{}) {
	method := "screenitem.Update"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "screenitemid": "20",
        "width": 500,
        "height": 300
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func ScreenitemGetData() (string,map[string]interface{}) {
	method := "screenitem.get"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "output": "extend",
        "screenids": "3"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func ScreenitemDelete(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := ScreenitemDeleteData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func ScreenitemUpdatebyposition(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := ScreenitemUpdatebypositionData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func ScreenitemUpdate(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := ScreenitemUpdateData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func ScreenitemGet(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := ScreenitemGetData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

